/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package thecliffproblem;

/**
 *
 * @author Jaime
 */
public class Coordinate {
    
    private int line;
    private int column;
    
    public Coordinate(int line, int column)
    {
        this.line = line;
        this.column = column;
        
    }
    
    /**
     * @return the line
     */
    public int getLine() {
        return line;
    }

    /**
     * @return the column
     */
    public int getColumn() {
        return column;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 97 * hash + this.line;
        hash = 97 * hash + this.column;
        return hash;
    }
    
    public boolean equals(Object otherCoordinate)
    {
        if(!(otherCoordinate instanceof Coordinate))
        {
            return false;
        }
        
        Coordinate other = (Coordinate)otherCoordinate;
        
        if(other.getLine() == getLine() && other.getColumn() == getColumn())
        {
            return true;
        }
        
        return false;
        
    }
    
    /**
     * Determines whether the current coordinate is within the retangle formed
     * by the two coordinates . This retangle has a diagonal that start in one
     * coordinate and end in the other (including the lines and columns of the coordinates). 
     * @param c1 First coordinate.
     * @param c2 Second coordinate.
     * @return True if the current coordinate is within the retangle formed by
     * c1 and c2, false otherwise. If c1 and c2 are in the same line or column,
     * returns true only if current is in the segment formed by c1 and c2. If
     * c1 and c2 are equal, return true only if current also equals them.
     */
    public boolean isWithin(Coordinate c1, Coordinate c2)
    {
        
        int lowestLine = c1.line < c2.line ? c1.line : c2.line;
        int highestLine = c1.line >= c2.line ? c1.line : c2.line;
        
        int lowestColumn = c1.column < c2.column ? c1.column : c2.column;
        int highestColumn = c1.column >= c2.column ? c1.column : c2.column;
        
        return getLine() >= lowestLine && getLine() <= highestLine &&
                getColumn() >= lowestColumn && getColumn() <= highestColumn;
    }
      
}
